package com.ideafactory.client.ybservice.ybviewpager;

import android.app.Dialog;
import android.content.Context;
import android.content.IntentFilter;
import android.os.RemoteException;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.gprinter.command.GpCom;
import com.ideafactory.client.afinal.NetConstants;
import com.ideafactory.client.beans.CatalogGoodsBean;
import com.ideafactory.client.beans.GoodsSureList;
import com.ideafactory.client.beans.OrderBaseInfoBean;
import com.ideafactory.client.beans.OrderGoodsBean;
import com.ideafactory.client.beans.TotalUpToServer;
import com.ideafactory.client.print.icod.IcodPrinterManager;
import com.ideafactory.client.utils.CommonUtils;
import com.ideafactory.client.utils.HeartBeatClient;
import com.ideafactory.client.utils.JsonForBean;
import com.ideafactory.client.utils.OnReceivedQuantityChange;
import com.ideafactory.client.utils.SpUtils;
import com.ideafactory.client.utils.TYTool;
import com.ideafactory.client.utils.TextVUtils;
import com.ideafactory.client.utils.netutils.MyCallBack;
import com.ideafactory.client.utils.netutils.NetUtils;
import com.ideafactory.client.views.CustomProgressDialog;
import com.ideafactory.client.views.DividerItemDecoration;
import com.ideafactory.client.views.GoodsEnsureAdapter;
import com.ideafactory.client.ybselfservice.R;
import com.ideafactory.client.ybservice.APP;
import com.ideafactory.client.ybservice.YbSelfService;
import com.lidroid.xutils.db.annotation.Check;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by LiuShao on 2016/5/24.
 */
public class GoodsEnsurePager extends GoodsBasePager {

    @ViewInject(R.id.rv_goods_ensure)
    private RecyclerView rv_goods_ensure;
    @ViewInject(R.id.tv_totoal_money)
    private TextView tv_totoal_money;
    private GoodsEnsureAdapter goodsEnsureAdapter;
    private List<CatalogGoodsBean> goodsList;
    @ViewInject(R.id.radio_checked)
    private RadioGroup radio_checked;
    @ViewInject(R.id.radio_eatting_in)
    private RadioButton radio_eatting_in;
    @ViewInject(R.id.radio_packing)
    private RadioButton radio_packing;
    @ViewInject(R.id.pack_show_money)
    private TextView pack_show_money;

    @ViewInject(R.id.btn_coupon)
    private Button btn_coupon;

    @ViewInject(R.id.layout_coupon)
    private LinearLayout layout_coupon;

    @ViewInject(R.id.iv_coupon_cancle)
    private ImageView iv_coupon_cancle;

    @ViewInject(R.id.tv_coupon_name)
    private TextView tv_coupon_name;

    public GoodsEnsurePager(Context context) {
        super(context);
    }

    @Override
    public View initView() {
        View view = View.inflate(context, R.layout.fragment_goods_ensure, null);
        x.view().inject(this, view);
        return view;
    }

    @Override
    public void initViewBuind() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(APP.getAPP().getApplicationContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rv_goods_ensure.setLayoutManager(linearLayoutManager);
        rv_goods_ensure.addItemDecoration(new DividerItemDecoration(30));
        updateCountMoney();

        setOnReceivedChangeMain(new OnReceivedChangeMain() {
            @Override
            public void changeToMain() {
                if (dialog!=null&&dialog.isShowing()){
                    dialog.dismiss();
                }
                if (Coupondialog != null && Coupondialog.isShowing()) {
                    Coupondialog.dismiss();
                }
        }
        });
    }

    private String isPackaging = "2";//是否打包
    private double totalMoney;//总价格
    private double packageMoney = 0;//单件打包的钱
    private double packAgeToTalMoney = 0;//打包的总钱
    private int isEatein;
    private int isPack;
    private static final int MAIN_QUERY_PRINTER_STATUS = 0xfe;
    @Override
    public void initData(int fromPager) {
        packageMoney = Double.valueOf(SpUtils.getString(APP.getAPP().getApplicationContext(), SpUtils.PACKING_MONEY, "0"));
        Map<String, Object> currentMap = (Map<String, Object>) getObj(GOODS_DETIAL_INT);
        if (currentMap != null) {
            totalMoney = (double) currentMap.get("totalMoney");
            goodsList = (List<CatalogGoodsBean>) currentMap.get("goodsData");
            if (goodsList != null) {
                packAgeToTalMoney = loadPackMoney(goodsList);
                goodsEnsureAdapter = new GoodsEnsureAdapter();
                goodsEnsureAdapter.setCatalogGoodsLists(goodsList);
                rv_goods_ensure.setAdapter(goodsEnsureAdapter);
            }
        }
        handPackChack();
        loadMoneyCount();
//        if (YbSelfService.mGpService!=null){
//            try {
//                YbSelfService.mGpService.queryPrinterStatus(0, 500, MAIN_QUERY_PRINTER_STATUS);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
    }

    private void handPackChack(){

        isEatein = SpUtils.getInt(APP.getAPP().getApplicationContext(), SpUtils.EATIN, 2);
        isPack = SpUtils.getInt(APP.getAPP().getApplicationContext(), SpUtils.PACKAGEING, 2);
        if (isEatein == 1) {
            if (isPack == 1) {
                radio_checked.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(RadioGroup group, int checkedId) {
                        switch (checkedId) {
                            case R.id.radio_eatting_in://堂食
                                isPackaging = "2";
                                setPackAgeMoney();
                                break;
                            case R.id.radio_packing://打包
                                isPackaging = "1";
                                setPackAgeMoney();
                                break;
                        }
                    }
                });
            } else {
                radio_checked.check(R.id.radio_eatting_in);
                radio_packing.setEnabled(false);
                isPackaging = "2";//堂食
                setPackAgeMoney();
            }
        } else {
            if (isPack == 1) {
                isPackaging = "1";//打包
                setPackAgeMoney();
                radio_checked.check(R.id.radio_packing);
                radio_eatting_in.setEnabled(false);
            }
        }
        radio_checked.check(R.id.radio_eatting_in);//默认选择堂食
    }

    /**
     * 计算打包总价格
     * @param catalogGoodsBeans
     * @return
     */
    private double loadPackMoney(List<CatalogGoodsBean> catalogGoodsBeans){
        double packMoney = 0;
        for (int i=0;i<catalogGoodsBeans.size();i++){
            if(catalogGoodsBeans.get(i).getIsPackCharge()==1){
                packMoney = CommonUtils.addNum(packMoney,CommonUtils.mulNum(catalogGoodsBeans.get(i).getPackMoney(),catalogGoodsBeans.get(i).getGoodsAdded()));
            }
        }
        return packMoney;
    }

    private void setPackAgeMoney() {
        loadMoneyCount();
        if(isPackaging.equals("1")){
//            pack_show_money.setVisibility(View.VISIBLE);//正常
            pack_show_money.setVisibility(View.GONE);//庆丰包子
        }else{
            pack_show_money.setVisibility(View.GONE);
        }
    }

    /**
     * 有加减操作时候的监听
     */
    private void updateCountMoney() {
        setOnReceivedQuantityChange(new OnReceivedQuantityChange() {
            @Override
            public void onReceivedAdd(double addMoney, int ispackage,double packmoney) {
                totalMoney = CommonUtils.addNum(totalMoney, addMoney);
                if(ispackage==1){
//                    packAgeToTalMoney = CommonUtils.addNum(packAgeToTalMoney, packageMoney);
                    packAgeToTalMoney = CommonUtils.addNum(packAgeToTalMoney,packmoney);
                    Log.e(TAG, "addMoney--------> "+packmoney );
                }
                loadMoneyCount();
            }
            @Override
            public void onReceivedSub(double subMoney, int ispackage,double packmoney) {
                totalMoney = CommonUtils.subNum(totalMoney, subMoney);
                if(ispackage==1){
                    packAgeToTalMoney = CommonUtils.subNum(packAgeToTalMoney, packmoney);
                }
                loadMoneyCount();
            }
            @Override
            public void onReceivedDelete(int position, int ispackage) {
                createDialog(position, context.getString(R.string.qdsccsp), ispackage);
            }
        });
    }

    //重新计算总的商品数量
    private void loadMoneyCount() {
        if(isPackaging.equals("1")){
            tv_totoal_money.setText(context.getString(R.string.zj)+context.getString(R.string.money_unit)  + TextVUtils.highlight(CommonUtils.addNum(totalMoney,packAgeToTalMoney) + ""));
            pack_show_money.setText(context.getString(R.string.coupon_packfee)+context.getString(R.string.money_unit) + packAgeToTalMoney +")");
        }else {
            tv_totoal_money.setText(context.getString(R.string.zj)+context.getString(R.string.money_unit) + TextVUtils.highlight(totalMoney + ""));
        }
    }

    /**
     *
     * @param position 删除某位置的条目
     * @param msg 消息
     * @param ispackage 1打包要钱 2 打包不要钱 0 做判断，是0的话删除全部
     */

    AlertDialog.Builder builder;
    AlertDialog dialog;
    public void createDialog(final int position, String msg,int ispackage) {
        builder = new AlertDialog.Builder(context);
        dialog = builder.create();
        WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
        params.width = 300;
        params.height = 200;
        dialog.getWindow().setAttributes(params);
        View view = View.inflate(APP.getAPP().getApplicationContext(), R.layout.dialog_show_delete_goods, null);
        Button btn_ensure = (Button) view.findViewById(R.id.btn_ensure);
        Button btn_cancle = (Button) view.findViewById(R.id.btn_cancle);
        TextView tv_goods_name = (TextView) view.findViewById(R.id.tv_goods_name);
        tv_goods_name.setText(msg);
        btn_ensure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (position == -1) {
                    onPagerChange.changePositon(GOODS_ENSURE_INT,MAIN_FRAGMENT);
                    System.gc();
                } else if(position == -2){
                    dialog.dismiss();
                    if (customProgressDialog != null && customProgressDialog.isShowing()) {
                        customProgressDialog.dismiss();
                    }
                }else {
                    goodsEnsureAdapter.clearPosition(position);
                }
            }
        });
        btn_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (customProgressDialog != null && customProgressDialog.isShowing()) {
                    customProgressDialog.dismiss();
                }
            }
        });
        dialog.setView(view);
        dialog.show();
    }

    public static OnReceivedQuantityChange onReceivedQuantityChange;
    public static void setOnReceivedQuantityChange(OnReceivedQuantityChange onReceivedQuantityChange) {
        GoodsEnsurePager.onReceivedQuantityChange = onReceivedQuantityChange;
    }
    private CustomProgressDialog customProgressDialog;

    @Event(value = {R.id.btn_goods_ensure_return, R.id.btn_goodensure_order_cancle, R.id.btn_goodensure_order_ok, R.id.btn_coupon, R.id.iv_coupon_cancle}, type = View.OnClickListener.class)
    private void btn_click(View view) {
        switch (view.getId()) {
            case R.id.btn_goods_ensure_return:
                setObj(GOODS_ENSURE_INT, goodsEnsureAdapter.getCatalogGoodsLists());
                onPagerChange.changePositon(GOODS_ENSURE_INT,GOODS_DETIAL_INT);
                break;
            case R.id.btn_goodensure_order_cancle:
                createDialog(-1, APP.getAPP().getResources().getString(R.string.qdxxdd),0);
                break;
            case R.id.btn_goodensure_order_ok:
                customProgressDialog = new CustomProgressDialog(context, "", R.drawable.frame);
                customProgressDialog.show();
                checkInfo();

                break;
            case R.id.btn_coupon:
                showCoupon();
                break;
            case R.id.iv_coupon_cancle:
                layout_coupon.setVisibility(View.GONE);
                btn_coupon.setVisibility(View.VISIBLE);
                isUseCoupon=false;
                break;
        }
    }
    private int[] buttons;      //数字按钮数组
    private  String str1;               //旧输入值
    private  Button temp;
    private double conValue;
    private double preValue=0d;
    private boolean isUseCoupon=false;
    private String preCode="";

    Dialog Coupondialog;
    private void showCoupon(){
        View view=View.inflate(context,R.layout.view_coupon, null);
        Coupondialog = new Dialog(context);
        Coupondialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        // 去掉dialog的title
        Coupondialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

        ImageView iv_cancel= (ImageView) view.findViewById(R.id.iv_cancel);
        Button btn_coupon_use= (Button) view.findViewById(R.id.btn_coupon_use);
        Button btn_back= (Button) view.findViewById(R.id.btn_back);
        Button btn_clear= (Button) view.findViewById(R.id.btn_clear);
        final TextView edit_input= (TextView) view.findViewById(R.id.edit_input);
        final TextView tv_tip= (TextView) view.findViewById(R.id.tv_tip);

        buttons = new int[]
                {       //记录数值按钮的id
                        R.id.btn_0, R.id.btn_1, R.id.btn_2, R.id.btn_3, R.id.btn_4,
                        R.id.btn_5, R.id.btn_6, R.id.btn_7, R.id.btn_8, R.id.btn_9
                };

        for (int i = 0; i < buttons.length; i++) {
            temp = (Button) view.findViewById(buttons[i]);
            temp.setOnClickListener(
                    new View.OnClickListener() {                     //内部类
                        @Override
                        public void onClick(View v)    //重写方法
                        {
                            str1 = edit_input.getText().toString().trim();    //得到textview中的字符串
                            str1 = str1 + String.valueOf(((Button) v).getText());
                            edit_input.setText(str1);
                        }
                    }
            );
        }
        btn_clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                edit_input.setText("");
            }
        });

        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String str = edit_input.getText().toString().trim();
                if (str.length() > 0) {
                    str1 = str.substring(0, str.length() - 1);
                    edit_input.setText(str1);
                }
            }
        });

        iv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Coupondialog!=null&&Coupondialog.isShowing()){
                    Coupondialog.dismiss();
                    isUseCoupon=false;
                }
            }
        });

        btn_coupon_use.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                preCode=edit_input.getText().toString().trim();
                String storeId= SpUtils.getString(context, SpUtils.STOREID, "");
                Map map = new HashMap();
                map.put("storeId",storeId);
                map.put("preCode",preCode);


                NetUtils.Post(NetConstants.GETCOUPON, map, new MyCallBack<String>() {

                    @Override
                    public void onSuccess(String result) {
                        Log.e(TAG, "优惠券-------------->" + result);
                        try {
                            JSONObject jsonObject = new JSONObject(result);
                            String status = (String) TYTool.getJsonObj(jsonObject, "status", "0");

                            if (status.equals("1")) {
                                try {
                                    conValue=jsonObject.getJSONObject("preferentialInfo").getDouble("conValue");
                                    preValue=jsonObject.getJSONObject("preferentialInfo").getDouble("preValue");
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                layout_coupon.setVisibility(View.VISIBLE);
                                btn_coupon.setVisibility(View.GONE);
                                isUseCoupon=true;
                                if (Coupondialog!=null&&Coupondialog.isShowing()){
                                    Coupondialog.dismiss();
                                }
                                tv_coupon_name.setText(context.getResources().getString(R.string.coupon_discount)+" -"+context.getResources().getString(R.string.money_unit)+preValue);
                            }else if (status.equals("2")){
                                Toast.makeText(context, context.getResources().getString(R.string.coupon_input_error), Toast.LENGTH_LONG).show();
                                tv_tip.setText(context.getResources().getString(R.string.coupon_input_error));
                            }else if (status.equals("3")){
                                Toast.makeText(context, context.getResources().getString(R.string.coupon_input_expired), Toast.LENGTH_LONG).show();
                                tv_tip.setText(context.getResources().getString(R.string.coupon_input_expired));
                            }else if (status.equals("4")){
                                Toast.makeText(context, context.getResources().getString(R.string.coupon_input_notdata), Toast.LENGTH_LONG).show();
                                tv_tip.setText(context.getResources().getString(R.string.coupon_input_notdata));
                            }else if (status.equals("5")){
                                Toast.makeText(context, context.getResources().getString(R.string.coupon_input_used), Toast.LENGTH_LONG).show();
                                tv_tip.setText( context.getResources().getString(R.string.coupon_input_used));
                            }
                            Log.i("status", result);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });


            }
        });

        Coupondialog.show();
        Coupondialog.setContentView(view);

    }
    private void checkInfo() {
//         String xmppStatus=NetUtils.getXmppConnected();
//        if (xmppStatus.equals("离线")){
//            customProgressDialog.dismiss();
//            Toast.makeText(context,"网络连接不正常，请联系店铺管理人员！",Toast.LENGTH_LONG).show();
//            return;
//        }

        int isLinked= YbSelfService.getPrinterStatus(YbSelfService.mUsbDev1);
        int iStatus = YbSelfService.checkStatus(isLinked);
//        if (iStatus!=0){
//            customProgressDialog.dismiss();
//            Toast.makeText(context,"小票打印机异常，请联系店铺管理人员！",Toast.LENGTH_LONG).show();
//            return;
//        }

        if (!isUseCoupon){
            upLoadToServer();
        }else {

            if(isPackaging.equals("1")){//打包
                upLoadToServer();
//                if (preValue<totalMoney+packAgeToTalMoney){
//
//                }else {
//                    layout_coupon.setVisibility(View.GONE);
//                    btn_coupon.setVisibility(View.VISIBLE);
//                    isUseCoupon=false;
//                    createDialog(-2,"订单金额必须大于优惠码金额才能使用优惠券,您确定要继续支付嘛",0);
//                }
            }else {//不打包

                upLoadToServer();
//                if (preValue<totalMoney){
//                    upLoadToServer();
//                }else {
//                    layout_coupon.setVisibility(View.GONE);
//                    btn_coupon.setVisibility(View.VISIBLE);
//                    isUseCoupon=false;
//                    createDialog(-2,"订单金额必须大于优惠码金额才能使用优惠券,您确定要继续支付嘛",0);
//                }
            }

        }
    }

    private static final String TAG = "GoodsEnsurePager";
    private void upLoadToServer() {

        TotalUpToServer totalUpToServer = new TotalUpToServer();
        totalUpToServer.setOrderFrom("1");
        totalUpToServer.setDeviceId(HeartBeatClient.getDeviceNo());



        totalUpToServer.setIsPack(isPackaging);
        if (isUseCoupon){
            totalUpToServer.setPreCode(preCode);
            totalUpToServer.setPreMoney(preValue);
        }else {
            totalUpToServer.setPreCode(null);
            totalUpToServer.setPreMoney(null);
        }
        totalUpToServer.setGoodsList(getNeeded());
        totalUpToServer.setGoodsCount(foodscount);
        Log.e(TAG, "foodscount---->"+foodscount );
        if (foodscount==0){
            Toast.makeText(context,APP.getAPP().getResources().getString(R.string.OrderCannotBeEmpty),Toast.LENGTH_SHORT).show();
            if (customProgressDialog!=null&&customProgressDialog.isShowing()){
                customProgressDialog.dismiss();
            }
            return;
        }

        if(isPackaging.equals("1")){

            if (isUseCoupon){
                DecimalFormat df = new DecimalFormat("#.00");
                totalUpToServer.setPackMoney(packAgeToTalMoney);
                totalUpToServer.setPreMoney(preValue);

                if (preValue<totalMoney+packAgeToTalMoney){
                    totalUpToServer.setAllMoney(String.valueOf(df.format(CommonUtils.addNum(totalMoney,packAgeToTalMoney)-preValue)));
                }else {
                    totalUpToServer.setAllMoney("0.00");
                }

            }else {
                totalUpToServer.setPackMoney(packAgeToTalMoney);
                totalUpToServer.setAllMoney(String.valueOf(CommonUtils.addNum(totalMoney,packAgeToTalMoney)));
            }
        }else{
            totalUpToServer.setPackMoney(0d);
            if (isUseCoupon){
                DecimalFormat df = new DecimalFormat("#.00");
                totalUpToServer.setPreMoney(preValue);
                if (preValue<totalMoney){
                    totalUpToServer.setAllMoney(String.valueOf(df.format(totalMoney-preValue)));
                }else {
                    totalUpToServer.setAllMoney("0.00");
                }

            }else {
                totalUpToServer.setAllMoney(String.valueOf(totalMoney));
            }
        }

        String jsonBeanList = JsonForBean.beanToString(totalUpToServer);

        Map map = new HashMap();
        map.put("orderInfoStr", jsonBeanList);

        Log.e(TAG, "jsonBeanList------>"+jsonBeanList );
        NetUtils.Post(NetConstants.SUBMIT_ORDER_INFO, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                System.out.println("result------>" + result);
                Log.e(TAG, "Goodsensure-------------->"+result );
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String status = (String) TYTool.getJsonObj(jsonObject, "status", "0");
                    if (status.equals("1")) {
                        toNext(result);
                    }
                    Log.i("status", result);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 后台传递数据成功，将订单传递给下个界面
     * @param orderBaseInfoString
     */
    private void toNext(String orderBaseInfoString) {
        customProgressDialog.dismiss();

        int isAliPay = SpUtils.getInt(APP.getAPP(), SpUtils.ISALIPAY, 0);
        int isWxPay = SpUtils.getInt(APP.getAPP(), SpUtils.ISWXPAY, 0);

        if (isAliPay == 1 || isWxPay == 1) {
            setObj(GOODS_ENSURE_INT, orderBaseInfoString);
            onPagerChange.changePositon(GOODS_ENSURE_INT,GOODS_PAY_INT);
        } else {
            com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(orderBaseInfoString);
            OrderBaseInfoBean baseInfoBean = JsonForBean.getPerson(jsonObject.getString("orderBaseInfo"), OrderBaseInfoBean.class);
            JSONArray jsonArray = jsonObject.getJSONArray("orderGoodsList");
            List<OrderGoodsBean> mList = JsonForBean.getPersonList(jsonArray.toString(), OrderGoodsBean.class);

            double realMoney = 0d;

            for (int i = 0; i < mList.size(); i++) {
                realMoney = realMoney + mList.get(i).getPrice() * mList.get(i).getCount();
            }

            realMoney = realMoney + baseInfoBean.getPackMoney();

            String shopName = SpUtils.getString(context, SpUtils.SHOP_NAME, "");
            String shopAddress = SpUtils.getString(context, SpUtils.SHOP_ADDRESS, "");

            YbSelfService.printSeatTest(mList, YbSelfService.mUsbDev1, shopName, shopAddress, baseInfoBean.getAllMoney() + "", baseInfoBean.getOrderSernum().replaceAll("busself", ""), baseInfoBean.getPackMoney() + "", baseInfoBean.getIsPack(), baseInfoBean.getPreMoney() + "", realMoney + "");
            IcodPrinterManager.getIns().printText(mList, YbSelfService.mUsbDev1, shopName, shopAddress, baseInfoBean.getAllMoney() + "", baseInfoBean.getOrderSernum().replaceAll("busself", ""), baseInfoBean.getPackMoney() + "", baseInfoBean.getIsPack(), baseInfoBean.getPreMoney() + "", realMoney + "");

            onPagerChange.changePositon(GOODS_ENSURE_INT,MAIN_FRAGMENT);
        }
    }

    private int foodscount;
    private List<GoodsSureList> getNeeded() {
        double allMoney = 0;
        goodsList = goodsEnsureAdapter.getCatalogGoodsLists();
        List<GoodsSureList> goodsToUp = new ArrayList<>();
        int size = goodsList.size();
        for (int i = 0; i < size; i++) {
            CatalogGoodsBean catalogGoodsBean = goodsList.get(i);
            foodscount += catalogGoodsBean.getGoodsAdded();
            allMoney = CommonUtils.addNum(allMoney, CommonUtils.mulNum(catalogGoodsBean.getPrice(), catalogGoodsBean.getGoodsAdded()));
            GoodsSureList goodsSureList = new GoodsSureList();
            goodsSureList.setId(catalogGoodsBean.getGoodsId());
            goodsSureList.setCount(String.valueOf(catalogGoodsBean.getGoodsAdded()));
            goodsSureList.setSubtotal(CommonUtils.mulNum(catalogGoodsBean.getPrice(), catalogGoodsBean.getGoodsAdded()));
            goodsToUp.add(goodsSureList);
        }
        return goodsToUp;
    }

    public interface OnReceivedChangeMain{
        void changeToMain();
    }
    public static OnReceivedChangeMain onReceivedChangeMain;
    public static void setOnReceivedChangeMain(OnReceivedChangeMain onReceivedChangeMain) {
        GoodsEnsurePager.onReceivedChangeMain = onReceivedChangeMain;
    }
}
